/*
 * Copyright (c) 2019 Author: Fancyears Milos Malvis @1243093366@qq.com
 * ALL COPYRIGHT REVERSED.
 */

package com.fancyears.mq.producer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * 只要用RabbitTemplate发送数据
 *
 * @Author: Fancyears Milos Malvis
 * @Date: Created in  2019/5/30 11:00
 * @Modified By:
 */
@Service
@Slf4j
public class MessageProducer {

    @Value("${rabbitmqDirectExchange}")
    String rabbitmqDirectExchange;
    @Value("${rabbitmqDirectExchange2}")
    String rabbitmqDirectExchange2;

    @Value("${rabbitmqDirectQueue}")
    String rabbitmqDirectQueue;
    @Value("${rabbitmqDirectQueue2}")
    String rabbitmqDirectQueue2;
    @Value("${task.direct.key}")
    String rabbitmqDirectKey;
    @Value("${task.direct.key2}")
    String rabbitmqDirectKey2;
    @Autowired
    @Qualifier("rabbitmqAmqpTemplate")
    RabbitTemplate rabbitTemplate;

    @Autowired
    @Qualifier("rabbitmqAmqpTemplate2")
    RabbitTemplate rabbitTemplate2;

    public void sendMessageToDirect(String message) {
        //发送消息
        rabbitTemplate.convertAndSend(rabbitmqDirectExchange, rabbitmqDirectKey, message);
    }

    public void sendMessageToDirect2(String message) {
        //发送消息
        rabbitTemplate2.convertAndSend(rabbitmqDirectExchange2, rabbitmqDirectKey2, message);
    }

}
